from pprint import pprint

import requests
from bs4 import BeautifulSoup
from lxml import etree


# 获取网页
def get_page():
    url = f'http://sports.sina.com.cn/nba/'
    headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        # response.content返回的是字节流
        return response.content.decode('utf-8')
    return None


def parse_page(html):
    # html = '<div><span>坚持努力</span></div>'
    soup = BeautifulSoup(html, 'lxml')
    # 整齐的格式输出
    # print(soup.prettify())
    # print(soup.title.string)


def main():
    html = get_page()
    # print(html)
    parse_page(html)


if __name__ == '__main__':
    main()
